#include "queue.h"
#include "def.h"

typedef struct
{
    struct dl_list head;
    uint32_t id;
    char name[128];
}person_t;

int queue_test(void)
{
    printf("** queue test:\n");
    queue_t *q = queue_create(NULL);
    assert(q);

    uint32_t i;
    person_t *person;
    for(i = 0; i < 1024; ++i){
        person = (person_t *)MALLOC(sizeof(person_t));
        assert(person);

        person->id = i;
        assert(queue_in(q, &person->head) == 0);
    }

    struct dl_list *item;
    for(i = 0; i < 1024; ++i){
        item = queue_out(q);
        assert(item);
        person = dl_list_entry(item, person_t, head);
        printf("id: %u\n", person->id);
        safe_free(person);
    }

    queue_destroy(&q, NULL);

    printf("** queue test success\n");
    return 0;
}
